package com.kingdee.pda.ui.fast_allot;

import android.content.Context;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.kingdee.pda.Api;
import com.kingdee.pda.entity.FastAllotRequestBean;
import com.kingdee.pda.entity.WarehouseAreaLocationInfo;

import java.util.HashMap;

/**
 * @author：dlj
 * @data：2021/9/8
 * @des：快速调拨Presenter
 */
public class FastAllotPresenter implements FastAllotContract.IFastAllotPresenter {
    private Context context;
    private FastAllotContract.IFastAllotView view;

    public FastAllotPresenter(Context context, FastAllotContract.IFastAllotView view) {
        this.context = context;
        this.view = view;
    }


    @Override
    public void fastallotOrderCommit(FastAllotRequestBean fastAllotRequestBean) {
        MyObserver myObserver = new MyObserver(context) {
            @Override
            public void onSuccess(BaseResponse result) {
                view.fastallotOrderCommitSuccess(result);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.fastallotOrderCommitFailed(msg);
            }
        };
        HttpUtils.request(Api.class)
                .fastallotOrderCommit(ConstantUtil.PDA_QTF_COMMIT, fastAllotRequestBean)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }

    @Override
    public void getDefaultLocationcode(HashMap<String, Object> map) {
        MyObserver<WarehouseAreaLocationInfo> myObserver = new MyObserver<WarehouseAreaLocationInfo>(context) {
            @Override
            public void onSuccess(BaseResponse<WarehouseAreaLocationInfo> result) {
                view.getDefaultLocationcodeSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
            }
        };
        HttpUtils.request(Api.class)
                .getDefaultLocationcode(ConstantUtil.GET_DEFAULT_LOCATIONCODE, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}
